package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.*;
import com.hualude.roadsign.service.RoadSignManageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by shao-yikun on 2017/4/7.
 */

@Controller
@RequestMapping("/rds_roadSignManageController")
public class RoadSignManageController {

    @Resource
    private RoadSignManageService roadSignManageService;

    @RequestMapping("/getRoadPoleCollect4DT")
    @ResponseBody
    public DTResponseDto getRoadPoleCollect4DT(DTRequestDto dtRequestDto,
                                               Integer orgId,
                                               String actorIds,
                                               String startRoad,
                                               String endRoad,
                                               String roadName,
                                               String saveState) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = roadSignManageService.getRoadPoleCollect4DT(dtRequestDto, orgId, actorIds, startRoad, endRoad, roadName, saveState);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/updateRoadPoleCollect")
    @ResponseBody
    public JsonMsgDto updateRoadPoleCollect(RoadpoleDto roadpoleDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.updateRoadPoleCollect(roadpoleDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/addRoadPoleCollect")
    @ResponseBody
    public JsonMsgDto addRoadPoleCollect(RoadpoleDto roadpoleDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.addRoadPoleCollect(roadpoleDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/deleteRoadPoleCollect")
    @ResponseBody
    public JsonMsgDto deleteRoadPoleCollect(String roadPoleIds) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.deleteRoadPoleCollect(roadPoleIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadSignCollect4DT")
    @ResponseBody
    public DTResponseDto getRoadSignCollect4DT(DTRequestDto dtRequestDto,
                                               Integer roadPoleId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = roadSignManageService.getRoadSignCollect4DT(dtRequestDto, roadPoleId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/getRoadSignCollect")
    @ResponseBody
    public JsonMsgDto getRoadSignCollect(Integer roadPoleId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {

            jsonMsgDto.setJsonData(roadSignManageService.getRoadSignCollect(roadPoleId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/updateRoadSignCollect")
    @ResponseBody
    public JsonMsgDto updateRoadSignCollect(RoadsignDto roadsignDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.updateRoadSignCollect(roadsignDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/addRoadSignCollect")
    @ResponseBody
    public JsonMsgDto addRoadSignCollect(RoadsignDto roadsignDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.addRoadSignCollect(roadsignDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/deleteRoadSignCollect")
    @ResponseBody
    public JsonMsgDto deleteRoadSignCollect(String roadSignIds) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.deleteRoadSignCollect(roadSignIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadPoleByRoadPoleId")
    @ResponseBody
    public JsonMsgDto getRoadPoleByRoadPoleId(Integer roadPoleId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.getRoadPoleByRoadPoleId(roadPoleId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }


    @RequestMapping("/getSignByRoadPoleId")
    @ResponseBody
    public JsonMsgDto getSignByRoadPoleId(Integer roadPoleId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.getSignByRoadPoleId(roadPoleId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCoordinateByOrgId")
    @ResponseBody
    public JsonMsgDto getCoordinateByOrgId(Integer orgId,
                                           String actorIds,
                                           double neLongitude,
                                           double neLatitude,
                                           double swLongitude,
                                           double swLatitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.getCoordinateByOrgId
                    (orgId, actorIds, neLongitude, neLatitude, swLongitude, swLatitude));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRegion4Select")
    @ResponseBody
    public JsonMsgDto getRegion4Select(Integer pid) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadSignManageService.getRegion4Select(pid));
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRegionIdByAddress")
    @ResponseBody
    public JsonMsgDto getRegionIdByAddress(String province, String city, String area) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadSignManageService.getRegionIdByAddress(province, city, area));
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadByRoadName")
    @ResponseBody
    public JsonMsgDto getRoadByRoadName(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadSignManageService.getRoadByRoadName(roadName, actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByRoadName")
    @ResponseBody
    public JsonMsgDto getSectionByRoadName(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadSignManageService.getSectionByRoadName(roadName, actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadPoleBySearch")
    @ResponseBody
    public JsonMsgDto getRoadPoleBySearch(Integer orgId, String actorIds, String strSearch, Integer mCount, Integer mySize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.getRoadPoleBySearch(orgId, actorIds, strSearch, mCount, mySize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadPole2Report4DT")
    @ResponseBody
    public DTResponseDto getRoadPole2Report4DT(DTRequestDto dtRequestDto, Integer orgId, Integer userId, String startRoad,
                                               String endRoad, Integer actorId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = roadSignManageService.getRoadPole2Report4DT(dtRequestDto, orgId, userId, startRoad, endRoad, actorId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/setRoadPoleMainOrg")
    @ResponseBody
    public JsonMsgDto setRoadPoleMainOrg(String roadPoleIds, Integer mainOrgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadSignManageService.setRoadPoleMainOrg(roadPoleIds, mainOrgId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadSignByRoadSignId")
    @ResponseBody
    public JsonMsgDto getRoadSignByRoadSignId(Integer roadSignId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.getRoadSignByRoadSignId(roadSignId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadByOrgId")
    @ResponseBody
    public JsonMsgDto getRoadByOrgId(Integer orgId, String city) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.getRoadByOrgId(orgId, city));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCityByOrgId")
    @ResponseBody
    public JsonMsgDto getCityByOrgId(Integer orgId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.getCityByOrgId(orgId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadPoleByFiltrate")
    @ResponseBody
    public JsonMsgDto getRoadPoleByFiltrate(String roadName, String city, Integer orgId, String actorIds) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.getRoadPoleByFiltrate(roadName, city, orgId, actorIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadPole4ReportDT")
    @ResponseBody
    public DTResponseDto getRoadPole4ReportDT(DTRequestDto dtRequestDto,
                                              Integer orgId,
                                              String actorIds,
                                              String startRoad,
                                              String endRoad,
                                              String roadName) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = roadSignManageService.getRoadPole4ReportDT(dtRequestDto, orgId, actorIds, startRoad, endRoad, roadName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/getHistory4DT")
    @ResponseBody
    public DTResponseDto getHistoryByRoadSignId(DTRequestDto dtRequestDto,
                                                Integer equipmentId,
                                                Integer equipmentType) {
        DTResponseDto dtRequestDto1 = new DTResponseDto();
        try {
            dtRequestDto1 = roadSignManageService.getHistory4DT(dtRequestDto, equipmentId, equipmentType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtRequestDto1;
    }

    @RequestMapping("/getHistory4APP")
    @ResponseBody
    public JsonMsgDto getHistory(Integer equipmentId,
                                 Integer equipmentType,
                                 Integer mCount,
                                 Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadSignManageService.getHistory4APP(
                    equipmentId, equipmentType, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

}
